package com.yanchangapp.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.text.TextUtils;
import android.widget.CheckBox;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.model.bean.GoodsApplyBean;
import com.zxl.baselib.util.ui.ResHelper;

import java.util.List;

import retrofit2.http.GET;

/**
 * Created by apple on 2019-08-22.
 * description:经营品种列表项 adapter
 */
public class GoodsApplyAdapter extends BaseQuickAdapter<GoodsApplyBean, BaseViewHolder> {

    public GoodsApplyAdapter(int layoutResId, @Nullable List<GoodsApplyBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsApplyBean item) {
        // 设置背景色...
        CardView cardView = helper.getView(R.id.cardApply);
        CheckBox checkBox = helper.getView(R.id.checkbox);
        checkBox.setChecked(item.isSelected());
        switch (item.getPurchaseStatus()){
            case 2:
                checkBox.setEnabled(true);
                helper.setVisible(R.id.ivPen,true);
                cardView.setCardBackgroundColor(ResHelper.getColor(R.color.must_bg));
                break;
            case 1:
                checkBox.setEnabled(true);
                helper.setVisible(R.id.ivPen,true);
                cardView.setCardBackgroundColor(ResHelper.getColor(R.color.sug_bg));
                break;
                case 0:
                    checkBox.setEnabled(false);
                    helper.setVisible(R.id.ivPen, false);
                    cardView.setCardBackgroundColor(ResHelper.getColor(R.color.normal_bg));
                    break;
        }

        // 设置标题
        helper.setText(R.id.tvTitle,item.getProductName());
        // 推荐数量...
        int number = item.getBuyNumber();
        if (number == 0){
            item.setBuyNumber(item.getRecommendNum());
        }
        if (TextUtils.isEmpty(item.getSupplierId())){
            item.setSupplierId(item.getSuppliers().get(0).getSupplierId());
            item.setSupplierName(item.getSuppliers().get(0).getSupplierName());
        }

        helper.setText(R.id.tvBuySize,String.valueOf(item.getBuyNumber()));
        // 设置实际库存
        helper.setText(R.id.tvRealStore, ResHelper.getString(R.string.real_store,
                item.getInventoryNumber(),item.getAlarmMin(),item.getAlarmMax()));
        // 设置点击事件...
        helper.addOnClickListener(R.id.checkbox).addOnClickListener(R.id.tvBuyShow);
    }
}
